{-# OPTIONS_HADDOCK prune, ignore-exports #-}
module TITypes
(
  Env,
  Environment,
  Expr(..),
  Type(..)
)
where

import Data.Map (Map)
import qualified Data.Map as Map

type Hypothesis = (Expr, Type)

type Env = [Hypothesis]

type Environment = Map Expr Type

data Expr = Var String  | App Expr Expr | Abs String Expr deriving (Eq, Ord)

instance Show Expr where
  show (Var name)                = name
  show (App exp1@(Abs _ _) exp2) = "(" ++ show exp1 ++ ")" ++ show exp2
  show (App expr (Var name))     = show expr ++ name
  show (App exp1 exp2)           = show exp1 ++ "(" ++ show exp2 ++ ")"
  show (Abs name expr)           = "\\" ++ name ++ "." ++ show expr


data Type = Const | TyVar String | Arrow Type Type deriving (Eq, Ord)

instance Show Type where
  show Const                     = "*"
  show (TyVar name)              = name
  show (Arrow Const        typ2) = "* -> " ++ show typ2
  show (Arrow (TyVar name) typ2) = name ++ " -> " ++ show typ2
  show (Arrow typ1         typ2) = "(" ++ show typ1 ++ ") -> " ++ show typ2

